package com.sjh.lib_app.net

import android.os.Build
import com.blankj.utilcode.util.AppUtils

import com.sjh.baseutils.toUrlEncode
import com.sjh.lib_app.UserConfig
import com.sjh.net.interceptor.BaseInterceptor
import okhttp3.Interceptor
import okhttp3.Response

/**
 * 向请求头添加一点信息
 * Created by Extends on 2018/2/5/005
 */
class HeadInfoInterceptor : BaseInterceptor() {
    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        request = request.newBuilder()
            .addHeader("SYSTEM-VERSION", "Android " + (Build.VERSION.RELEASE).toUrlEncode())
            .addHeader("PHONE-BRAND", (Build.BRAND).toUrlEncode())
            .addHeader("PHONE-MODELS", (Build.MODEL).toUrlEncode())
            .addHeader("ROM-VERSION", (Build.VERSION.INCREMENTAL).toUrlEncode())
            .addHeader("SOFTWARE-VERSION", (AppUtils.getAppVersionName()).toUrlEncode())
            .addHeader("REQUEST-TIME", System.currentTimeMillis().toString())
            .addHeader("Accept","application/vnd.RYuzhuaApp.v1+json")
            .addHeader("plateform" , "helper")
            .addHeader("X-token",UserConfig.token)
//            .apply {
//                if (UserConfig.isLogin()){
//                    addHeader("Authorization", "Bearer ${UserConfig.token}")
//                }
//            }
            .build()
        return chain.proceed(request)
    }


}